package com.ling.luo.user.controller;

import com.ling.luo.user.entity.User;
import com.ling.luo.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据id查找用户
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public User findById(String id) {
        return userService.getByUserId(id);
    }

    /**
     * 查找用户列表
     * @return
     */
    @GetMapping("/getAll")
    public List<User> findUserList() {
        return userService.list();
    }

    /**
     * 更新用户
     * @param user
     * @return
     */
    @PutMapping("/update")
    public User update(@RequestBody User user) {
        return userService.updateUser(user);
    }

    /**
     * 通过id删除用户
     * @param id
     */
    @DeleteMapping("/detele")
    public void delete(String id) {
        userService.deleteById(id);
    }
}
